local M = _G.ClientOHOH.class.new(script,_G.ClientOHOH.files.Client_PlayerComponent(),script.Parent.Name)
local ClientOHOH = _G.ClientOHOH
local PotionsGui = ClientOHOH.load.UIManager():CreateUI("PotionsGui",require(script.PotionsGui))
local CallBackManager = ClientOHOH.load.CallBackManager();
local Buff_Cfg=_G.CommonOHOH.config.Buff
local ConnectClass = _G.CommonOHOH.load.Connect();
local GlobalTipGui = ClientOHOH.load.UIManager().ui_list.GlobalTipGui;
local FunctionList = ClientOHOH.load.FunctionList();
local GeneralTool=_G.CommonOHOH.load.GeneralTool();
local UIManager = ClientOHOH.load.UIManager();
local LanguageHelper=_G.LanguageHelper 
function M.new(self,...)
    return M(self,...)
end

function M.ctor(self,parent)
    M.super.ctor(self,parent)
    self.DataStore = self.parent:GetComponent(_G.ClientOHOH.load.Client_PlayerDataComponent())
    self.player = parent
    self.usingPotionsList = {}
    self:AddConnect()
    PotionsGui:SetDatabase(self.DataStore)
    PotionsGui:Init()
end

function M.AddConnect(self)
    self.player.UserDataEvent:Connect(function(data)
        if data["buff"] then
            -- print("buff:---------------")
            -- print(data["buff"])
            PotionsGui:Clear()
            PotionsGui:Init()
        end
    end)

    PotionsGui.UsePotionsEvent:Connect(function(potionId,count)
        if count==0 then
            return
        end
        local buffList = self.DataStore:GetData("buff")
        if buffList[potionId] then
            if count>buffList[potionId] then
                GlobalTipGui:Show(LanguageHelper:GetText(30009))
            else
                local time = Buff_Cfg[potionId].time*count
                local icon = Buff_Cfg[potionId].icon
                if self.usingPotionsList[potionId] then
                    self.usingPotionsList[potionId].connect:Disconnect()
                    local newTime = self.usingPotionsList[potionId].leftTime+time
                    self.usingPotionsList[potionId].connect=UIManager.ui_list.HomeGui:CountDown( self.usingPotionsList[potionId],newTime)
                else
                    local potion = UIManager.ui_list.HomeGui:CreatePotionCell(icon,time,potionId)
                    self.usingPotionsList[potionId] = potion
                end
                if not self.RngDataCtrl then
                    self.RngDataCtrl = self.player:GetComponent(_G.CommonOHOH.load.Common_RngDataLayer())
                end
                if not self.BuffCtrl then
                    self.BuffCtrl = self.player:GetComponent(_G.CommonOHOH.load.Common_BuffCtrl())
                end
                self.BuffCtrl:CreateBuff(potionId)
                self:Invoke(FunctionList.use_potions,potionId,-count)
            end
        end
    end)
end



function M.dtor(self)
    M.super.dtor(self)
end

return M 